package com.onlineclass.util;

import java.util.HashMap;
import java.util.Set;

import com.cloopen.rest.sdk.CCPRestSDK;

/**
 * 荣联发送短信接口
 * @author david
 *
 */
public class SendSMSFromRongLian {

	/**
	 * 发短信
	 * @param mobile
	 */
	public static String send(Integer code, String mobile) {
		HashMap<String, Object> result = null;

		CCPRestSDK restAPI = new CCPRestSDK();
		restAPI.init("app.cloopen.com", "8883");// 初始化服务器地址和端口，格式如下，服务器地址不需要写https://
		restAPI.setAccount("8aaf070870e20ea101710a590f7514f7", "a7cb4b5d253d4f1d9acc73c384a5e80d");// 初始化主帐号和主帐号TOKEN
		restAPI.setAppId("8aaf070870e20ea101710a590fe414fe");// 初始化应用ID

		result = restAPI.sendTemplateSMS(mobile, "1", new String[] { String.valueOf(code), "10" });

		System.out.println("SDKTestSendTemplateSMS result=" + result);

		if ("000000".equals(result.get("statusCode"))) {
			// 正常返回输出data包体信息（map）
			HashMap<String, Object> data = (HashMap<String, Object>) result.get("data");
			Set<String> keySet = data.keySet();
			for (String key : keySet) {
				Object object = data.get(key);
				System.out.println(key + " = " + object);
			}
		} else {
			// 异常返回输出错误码和错误信息
			System.out.println("错误码=" + result.get("statusCode") + " 错误信息= " + result.get("statusMsg"));
		}
		return (String) result.get("statusCode");
	}
}
